package com.gurumades.jsonform.server.forms.dispatch.handlers;

import net.customware.gwt.dispatch.server.ActionHandler;
import net.customware.gwt.dispatch.server.ExecutionContext;
import net.customware.gwt.dispatch.shared.DispatchException;

import com.gurumades.jsonform.shared.dispatch.GetUploadUrlAction;
import com.gurumades.jsonform.shared.dispatch.GetUploadUrlResult;

public class GetUploadUrlHandler implements ActionHandler<GetUploadUrlAction, GetUploadUrlResult>{
	
	protected static UploadUrlProvider provider;
	
	public GetUploadUrlHandler() {
		super();
	}

	@Override
	public Class<GetUploadUrlAction> getActionType() {
		return GetUploadUrlAction.class;
	}

	@Override
	public GetUploadUrlResult execute(GetUploadUrlAction action,
			ExecutionContext context) throws DispatchException {
		return new GetUploadUrlResult(provider.getUploadUrl());
	}

	@Override
	public void rollback(GetUploadUrlAction action, GetUploadUrlResult result,
			ExecutionContext context) throws DispatchException {
		
	}
	
	public static void setProvider(UploadUrlProvider provider) {
		GetUploadUrlHandler.provider = provider;
	}
	
	public interface UploadUrlProvider{
		public String getUploadUrl();
	}

}
